package com.rd.student.jike.class2.lihongming.week731_806.Day0731;

import java.util.*;

/**
 * @Auther:Heinrich
 * @Date:2023/8/1-08-01-8:24
 * @Description:com.rd.student.jike.class2.lihongming.Day0731
 * @version:1.0
 */
public class ArrayRandom {
    public static int Num  =20;
    public static int Max = 50;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入随机个数");
        Num = scanner.nextInt();
        System.out.println("请输入随机数最大值");
        Max = scanner.nextInt();
        System.out.println("长");
        int len = scanner.nextInt();
        System.out.println("宽");
        int wide = scanner.nextInt();
        if (len*wide!=Num){
            System.out.println("输入不规范");
        }
        int[][] array = randomArray(len,wide);
        for (int i = 0; i < array.length; i++) {
            System.out.println(Arrays.toString(array[i]));
        }
    }
    public static int[][] randomArray(int len,int wide){
        int[][] array = new int[len][wide];
        for (int i = 0; i < array.length; i++) {
            Arrays.fill(array[i], -1);
        }
        HashSet<Integer> set = test01.randomNum(Num,Max);
        Iterator<Integer> iterator = set.iterator();
        int size = set.size();
        while (iterator.hasNext()) {
            int a = (int) (Math.random() * len);
            int b = (int) (Math.random() * wide);
            while (array[a][b] != -1) {
                a = (int) (Math.random() * len);
                b = (int) (Math.random() * wide);
            }
            array[a][b] = iterator.next();
            //set.remove(array[a][b]);
        }
        return array;
    }
}
